package fr.fermat.lyricsext;

import fr.fermat.control.Controller;
import android.app.Fragment;
import android.app.SearchManager;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class WebFragment extends Fragment{
	
	private Controller controller;
	private MainActivity activity;
	private WebView webView ;
	private String searchTerm ;
	private String URL ;
	/**
	 * Creates the fragment
	 */
	public WebFragment() {
		super();
	}
	
//	/**
//	 * Creates the Fragments
//	 */
//	public WebFragment(Controller controller) {
//		super();
//		this.controller = controller;
//	}
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}

	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
	}

	/**
	 * Initializes the Fragment
	 */
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.web, container, false);
		initialize(view);
		
		return view;
	}

	private void initialize(View view) {
		// TODO Auto-generated method stub
		
		searchTerm ="lyrics "+((MainActivity)getActivity()).getArtistName()+" "
	               +((MainActivity)getActivity()).getTrackName();
		
		webView = (WebView)view.findViewById(R.id.webView1);
		
		URL = "http://www.google.com/search?"
              +"&q="+searchTerm;
	
		webView.setWebViewClient(new WebViewClient());
		webView.getSettings().setJavaScriptEnabled(true);
		webView.loadUrl(URL);
	}
	
	public WebView getWebView(){
		return webView;
	}

	@Override
	public void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
	}

	@Override
	public void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
	}

}
